package com.cdivtc.management.controller;


import com.cdivtc.management.pojo.Clazz;
import com.cdivtc.management.pojo.Collage;
import com.cdivtc.management.pojo.Major;
import com.cdivtc.management.pojo.Result;
import com.cdivtc.management.service.ClazzAndCollage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("api")
public class ClazzAndCollageController {
    @Autowired
    private ClazzAndCollage clazzAndCollage;

    //    查询专业
    @RequestMapping("/querybycolid")
    public Result queryAllClazz(String colid) {
        return new Result().ok().addData(clazzAndCollage.queryAllClazz(colid));
    }

    //    查询所有学院
    @RequestMapping("/queryallcollage")

    public Result queryAllCollage() {
        return new Result().ok().addData(clazzAndCollage.queryAllCollage());
    }
    //    根据专业查班级
    @RequestMapping("/querybymajorid")

    public Result queryBymajorId(String majorid) {
        return new Result().ok().addData(clazzAndCollage.queryBymajorId(majorid));
    }
    //    查询所有的班级 专业名+班级
    @RequestMapping("/QueryMajorAndClazz")
    public Result QueryMajorAndClazz() {
        List<Clazz> clazzes = clazzAndCollage.queryByMajorAndClazzAll();

        return new Result().ok().addData(clazzes);
    }

    // 添加学院
    @PostMapping("/addCollege")
    public Result addCollege(@RequestBody Collage collage) {
        clazzAndCollage.addCollege(collage);
        return new Result().ok();
    }

    @PostMapping("/addMajor")
    public Result addMajor(@RequestBody Major major) {
        clazzAndCollage.addMajor(major);
        return new Result().ok();
    }

    @PostMapping("/addClazz")
    public Result addClazz(@RequestBody Clazz clazz) {
        clazzAndCollage.addClazz(clazz);
        return new Result().ok();
    }


}
